const { JSDOM } = require("jsdom");

module.exports = getNewsList;

function getNewsList(link) {
  return JSDOM.fromURL(link).then((dom) => {
    let list = [];
    let document = dom.window.document;

    document
      .getElementById("main-section")
      .querySelectorAll("article:not(.has-audio, .resaudio)")
      .forEach((e) => {
        let title = e.querySelector(".title"),
          url = title.querySelector("a").href;
        list.push({ title: title.textContent, url: url });
      });

    return list;
  });
}
